package redick;

import redick.analysis.*;
import redick.node.*;

import java.io.*;


class Translation extends DepthFirstAdapter {

	static String verb = "";
	static String arg1;
	static String arg2;
	Verb v;
	Object lisp_object;
	Environment env;

	Translation () {
		env = new Environment();
		env.put("x", 12.0);
		System.out.println("env in constructor is" + env);
	}

	public void outARepl(ARepl node) {
		System.out.println(lisp_object);
	}
	public void outAIdentifierTerm(AIdentifierTerm node) {
		String lkup = node.getIdentifier().getText();
		Object val = env.get(lkup);
		System.out.println("value of " + lkup + "is: " + val);
		System.out.println("env is" + env);
	}
	public void inAMinusDyad(AMinusDyad node) { v = new Verb("-"); }
	public void inAPlusDyad(APlusDyad node) {	v = new Verb("+");	}
	public void inATimesDyad(ATimesDyad node) {	v = new Verb("*");	}
	public void inADivisionDyad(ADivisionDyad node) {	v = new Verb("/");	}
	public void inARecipMonad(ARecipMonad node) {	v = new Verb("%");	}
	public void inAMexprExpr(AMexprExpr node) {
		v = new Verb( node.getMonad().toString() ) ;
		}
	public void inAStringTerm(AStringTerm node) {
		System.out.println( "SL: " + node.getStringLiteral() );
		}


	public void outAArg1(AArg1 node) {
		v.setD1(node.getArg().toString());
	}
	public void outAArg2(AArg2 node) {
		v.setD2(node.getArg().toString());
	}

	public void finalProc() {
		//System.out.println("Verb: " + v);
		Double retval = 0.0;
		retval = v.apply();
		System.out.println(retval);
	}
	public void outADexprExpr(ADexprExpr node) {
		finalProc();
	}
	public void outAMexprExpr(AMexprExpr node) {
		finalProc();
	}

}